home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / lib / file-output.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-27  |  2.2 KB  |  74 lines

  1. /* file-output.c: file writing routines for binary files in BigEndian
  2.    order, 2's complement representation.
  3.  
  4. Copyright (C) 1992 Free Software Foundation, Inc.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "config.h"
  21.  
  22. #include "file-output.h"
  23.  
  24.  
  25. /* Output in BigEndian order.  We could do these more efficiently by
  26.    checking if the hardware already uses BigEndian order, but it's not
  27.    worth it.  These routines are never the bottleneck (in the ways
  28.    they've been used so far, anyway).  We assume that we write negative
  29.    numbers in 2's complement, also.  */
  30.  
  31. void
  32. put_byte (one_byte b, FILE *f, string filename)
  33. {
  34.   if (fwrite (&b, 1, 1, f) != 1)
  35.     FATAL2 ("%s: Could not write byte %u", filename, b);
  36. }
  37.  
  38.  
  39. void
  40. put_two (two_bytes b, FILE *f, string filename)
  41. {
  42.   put_byte ((b & 0xff00) >> 8, f, filename); /* High-order byte.  */
  43.   put_byte (b & 0x00ff, f, filename);        /* And low-order.   */
  44. }
  45.  
  46.  
  47. void
  48. put_three (four_bytes b, FILE *f, string filename)
  49. {
  50.   put_byte ((b & 0x00ff0000) >> 16, f, filename);
  51.   put_byte ((b & 0x0000ff00) >> 8, f, filename);
  52.   put_byte (b & 0x000000ff, f, filename);
  53. }
  54.  
  55.  
  56. void
  57. put_four (four_bytes b, FILE *f, string filename)
  58. {
  59.   put_byte ((b & 0xff000000) >> 24, f, filename);
  60.   put_byte ((b & 0x00ff0000) >> 16, f, filename);
  61.   put_byte ((b & 0x0000ff00) >> 8, f, filename);
  62.   put_byte (b & 0x000000ff, f, filename);
  63. }
  64.  
  65.  
  66. void
  67. put_n_bytes (unsigned n, address b, FILE *f, string filename)
  68. {
  69.   one_byte *data_b = b;  /* We can't dereference a pure `address'.  */
  70.  
  71.   if (fwrite (data_b, n, 1, f) != 1)
  72.     FATAL2 ("%s: Could not write %u-byte block", filename, n);
  73. }
  74.